from dataholder import dataholder
import logging
from math import sqrt

class pointholder():
    min_basic_colors=4
    pointlist=[]# filed with tuples (type,x,y) 
    # type -  0 is rellative (to the canvas) and 1 is absolut 
    # if relative (type=0) x and y is between 0.0 - 1.0
    def __init__(self,dh=dataholder(),canvas=(640,480)):
        self.dh=dh;
        self.canvas=canvas
        #golden ratio
        phi=((1.0+sqrt(5.0))/2.0)
        a=1.0/phi
        b=1-a
        #A tuple with basic values between 0 and 1. 
        basic_nr=(0.0 , 0.25 , 1.0/3.0 , 0.5, a , b , 2.0/3.0, 0.75 , 1.0)
        #create startingpoints 1-10
        nr_of_points=1+self.dh.get0to(9)
        l=len(basic_nr)-1
        for i in range(nr_of_points):
            x=basic_nr[self.dh.get0to(l)]
            y=basic_nr[self.dh.get0to(l)]
            self.pointlist.append((0,x,y))

    def getpoint(self):
        l=len(self.pointlist)
        pos=self.dh.get0to(l) #get one point depending on the outcom from dataholder
        point=self.pointlist[pos]
        p,x,y=point[0],point[1],point[2]
        #if the point is rellaive to canvas, make it absolut by multibplying with canvas max and min
        if(p==0):
            x=int(float(x)*float(canvas[0]))
            y=int(float(y)*float(canvas[1]))
        return (x,y)
    
        


if __name__ == "__main__":
    data=dataholder("Johan")
    points=pointholder(data)
    print points.pointlist
